<template>
  <div class="L-margin-top-20">

    <van-cell-group inset>
      <div class="L-form-title-row">
        <div>
          <i class="iconfont icon-yuanzhu" style="color:#1683f7"></i>
          <span class="L-text L-primary-text-color">修改信息</span>
        </div>

      </div>
      <van-field v-model="phone" required label="手机" placeholder="请输入手机" />
      <van-field v-model="mail" required label="邮箱" placeholder="请输入邮箱" />

    </van-cell-group>

  </div>
  <div class="L-margin-top-40 L-text-align-center">
    <van-button @click="handleSubmit" type="primary" round size="large" class="L-login-btn">提交</van-button>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from "vue-router";
const router = useRouter();

import { showLoadingToast, closeToast, showToast } from "vant";
import { apiConfigurable } from "@/request/api/api";
import { ref, onMounted } from "vue";
const phone = ref("");
const mail = ref("");
onMounted(() => {
  getData();
});

function getData() {
  showLoadingToast({
    message: "加载中...",
    forbidClick: true,
    duration: 0,
  });
  const url = `employee.updategetinfo.do`;

  apiConfigurable(url).then((res) => {
    if (res.code === 0) {
      phone.value = res.data.phone;
      mail.value = res.data.mail;

      closeToast();
    }
  });
}

function handleSubmit() {
  showLoadingToast({
    message: "加载中...",
    forbidClick: true,
    duration: 0,
  });
  const url = `employee.updatemobile.do`;
  const data = {
    phone:phone.value,
    mail:mail.value
  }

  apiConfigurable(url,data).then((res) => {
    if (res.code === 0) {
      showToast("修改成功")
      setTimeout(()=>{
        router.go(-1)
      },2000)
      // closeToast();
    }
  });
}
</script>

<style scoped>
</style>